package com.lv.suyiyong.hfr.adapter

import android.view.View
import android.widget.TextView
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.recyclerview.widget.RecyclerView
import com.blankj.utilcode.util.SizeUtils
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.google.android.material.imageview.ShapeableImageView
import com.lv.common.imp.OnPositionTListener
import com.lv.common.ktx.LoadSrc
import com.lv.common.utils.MoneyUtil
import com.lv.service.bean.GoodsItemBean
import com.lv.suyiyong.hfr.R

/**
 * 作者： ygx
 * 创建日期：2022/6/24 8:10 PM
 * 签名： 天行健，君子以自强不息；地势坤，君子以厚德载物。
 *      _              _           _     _   ____  _             _ _
 *     / \   _ __   __| |_ __ ___ (_) __| | / ___|| |_ _   _  __| (_) ___
 *    / _ \ | '_ \ / _` | '__/ _ \| |/ _` | \___ \| __| | | |/ _` | |/ _ \
 *   / ___ \| | | | (_| | | | (_) | | (_| |  ___) | |_| |_| | (_| | | (_) |
 *  /_/   \_\_| |_|\__,_|_|  \___/|_|\__,_| |____/ \__|\__,_|\__,_|_|\___/
 *
 * You never know what you can do until you try !
 * ----------------------------------------------------------------
 *
 */
class GoodsHAdapter(
    private val datas: MutableList<GoodsItemBean>?,
    private val layout: Int = R.layout.item_company_goods_h
) :
    BaseQuickAdapter<GoodsItemBean, BaseViewHolder>
        (layout, datas) {

    override fun convert(holder: BaseViewHolder, item: GoodsItemBean) {
        val layoutPosition = holder.layoutPosition
        val clContainers = holder.getView<ConstraintLayout>(R.id.cl_containers)
        val mIvImg = holder.getView<ShapeableImageView>(R.id.iv_image)
        val mTvUnit = holder.getView<TextView>(R.id.tv_unit)
        val mTvPrice = holder.getView<TextView>(R.id.tv_price)
        val mTvContent = holder.getView<TextView>(R.id.tv_content)
//        val url = item.image?.urlAddBorder(
//            item.backdrop,
//            SizeUtils.dp2px(98.0f), 80
//        )
        mIvImg.LoadSrc(item.image ?: "")
        mTvContent.text = item.name
        val price = item.reducedprice ?: 0.0
        if (price == 0.0) {
            mTvUnit.visibility = View.GONE
            mTvPrice.text = "面议"
        } else {
            mTvUnit.visibility = View.VISIBLE
            val priceStr = MoneyUtil.moneydiv("$price", "100")
            mTvPrice.text = priceStr
        }
        clContainers.setOnClickListener {
            onViewItemClickListener?.onClick(layoutPosition, item)
        }

    }

    var onViewItemClickListener: OnPositionTListener<GoodsItemBean>? = null

}